using System;
using System.Collections.Generic;
using System.Linq;
using Baddies;
using Baddies.GUI;
using Baddies.InputDevices;
using Baddies.Scenes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace BaddiesGame
{
    /// <summary>
    /// This is the main type for your game.
    /// </summary>
    public class BaddiesGame : CoreGame
    {        
        /// <summary>
        /// Initializes a new instance of the BaddiesGame class.
        /// </summary>
        public BaddiesGame() : base()
        {            
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            this.root = new Scene();
            this.root.ParentRelativePos = false;
            this.root.Enter();

            BoxGUI box = new BoxGUI();
            box.Position = new Vector3(0, 0, 1);
            box.W = 20;
            box.H = 15;
            box.Name = "Box";
            box.ChangeBGColor(Color.Blue);

            BoxGUI box2 = new BoxGUI();
            box2.Position = new Vector3(6, 6, 2);
            box2.W = 20;
            box2.H = 15;
            box2.Name = "box2";
            box2.ChangeBGColor(Color.Brown);

            ConsoleGUI consoleGui = new ConsoleGUI();

            InputDevice inputDevice = new InputDevice();
            inputDevice.Position = new Vector3(0, 0, 1);
            inputDevice.Name = "iDevice";
            inputDevice.Add(0, box);
            inputDevice.Add(1, consoleGui);
            inputDevice.Add(2, box2);
            inputDevice.FocusedNode = consoleGui;

            Camera cam = new Camera(100, 100);
            cam.Position = new Vector3(-10, -10, 0);
            cam.Name = "Cam";

            Baddies.Console console = new Baddies.Console();

            this.root.Add(0, cam);
            this.root.Add(1, inputDevice);
            this.root.Add(2, console); 
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            this.root.NodeUpdate();

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            this.spriteBatch.Begin();
            this.root.NodeDraw(this.spriteBatch);
            this.spriteBatch.End();
        }
    }
}
